package cc.catface.base.net;

import android.annotation.SuppressLint;

import java.util.HashMap;
import java.util.Map;

import cc.catface.base.net.core.BizObserver;
import cc.catface.base.net.core.RetrofitHelper;
import cc.catface.base.net.domain.ResultBody;
import io.reactivex.Observable;
import io.reactivex.Observer;
import io.reactivex.android.schedulers.AndroidSchedulers;
import io.reactivex.schedulers.Schedulers;

public class RequestCenter {

    public static void time(BizObserver<String> observer) {
        String url = "http://172.17.25.156:9001/test/time";
        dispatch(RetrofitHelper.getApi().time(url), observer);
    }

    public static void paramE(ResultBody body, BizObserver<ResultBody> observer) {
        String url = "http://172.17.25.156:9001/test/paramE";
        Map<String, String> map = new HashMap<>();
        map.put("k1", "哈哈");
        map.put("k2", "呵呵");
        dispatch(RetrofitHelper.getApi().paramE(url, map, body), observer);
    }

    /** 线程调度 */
    private static <T> void dispatch(Observable<T> observable, Observer<T> observer) {
        observable.subscribeOn(Schedulers.io()).observeOn(AndroidSchedulers.mainThread(), false, 200).subscribe(observer);
    }
}

